﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace control
{
    class Command
    {
        private view.Menu _menu;
        private view.MemberCommands _viewMemberCommands;
        private model.MemberCommands _modelMemberCommands;
        private view.BoatCommands _viewBoatCommands;
        private model.BoatCommands _modelBoatCommands;

        public Command()
        {
            _menu = new view.Menu();
            _viewMemberCommands = new view.MemberCommands();
            _modelMemberCommands = new model.MemberCommands();
            _viewBoatCommands = new view.BoatCommands();
            _modelBoatCommands = new model.BoatCommands();
        }

        internal view.BoatCommands BoatCommands
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        internal view.MemberCommands MemberCommands
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        internal model.BoatCommands BoatCommands1
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        internal model.MemberCommands MemberCommands1
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        internal view.Menu Menu
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public void processCommand()
        {
            while (true)
            {
                //try
                //{
                    view.Commands command = _menu.getMenuChoice();
                    switch (command)
                    {
                        case view.Commands.getMembersBrief:
                            showAllMembers();
                            break;
                        case view.Commands.getMembersFull:
                            showAllMembersFull();
                            break;
                        case view.Commands.addMember:
                            addMember();
                            break;
                        case view.Commands.removeMember:
                            removeMember();
                            break;
                        case view.Commands.updateMember:
                            updateMember();
                            break;
                        case view.Commands.memberDetails:
                            memberDetails();
                            break;
                        case view.Commands.registerBoat:
                            registerBoat();
                            break;
                        case view.Commands.removeBoat:
                            removeBoat();
                            break;
                        case view.Commands.updateBoat:
                            updateBoat();
                            break;
                        case view.Commands.exit:
                            return;
                        default:
                            throw new InvalidOperationException();
                    }
                //}
                //catch (Exception)
                //{
                //    _viewMemberCommands.commandAborted();
                //}
                Console.WriteLine();
                Console.WriteLine("Tryck på valfri tangent för att fortsätta.");
                Console.ReadKey();
            }
        }

        private void updateBoat()
        {
            _modelBoatCommands.updateBoat(_viewBoatCommands.updateBoat(
                _viewBoatCommands.getBoat()));
            _viewBoatCommands.updateBoatSuccess();
        }

        private void removeBoat()
        {
            _modelBoatCommands.deleteBoat(_viewBoatCommands.getBoat());
            _viewBoatCommands.removeBoatSuccess();
        }

        private void registerBoat()
        {
            model.Boat boat = _viewBoatCommands.getNewBoat();
            model.Member member = _viewMemberCommands.getBoatOwner();
            _modelMemberCommands.addBoatToMember(boat, member);
            _viewBoatCommands.registerBoatSuccess();
        }

        private void memberDetails()
        {
            _viewMemberCommands.showMemberDetails(_viewMemberCommands.getMember());
        }

        private void updateMember()
        {
            _modelMemberCommands.updateMember(_viewMemberCommands.updateMember(
                _viewMemberCommands.getMember()));
            _viewMemberCommands.updatedMemberSuccess();
        }

        private void removeMember()
        {
            _modelMemberCommands.deleteMember(_viewMemberCommands.getMember());
            _viewMemberCommands.removeMemberSuccess();
        }

        private void addMember()
        {
            _modelMemberCommands.registerMember(_viewMemberCommands.getNewMember());
            _viewMemberCommands.addMemberSuccess();
        }

        private void showAllMembersFull()
        {
            _viewMemberCommands.showMembersFull();
        }

        private void showAllMembers()
        {
            _viewMemberCommands.showAllMembersBrief();
        }
    }
}
